Skip to content

C++: Fix join-order problem in getNextSwitchCase#21765

Merged
jketema merged 4 commits intogithub:mainfrom
jketema:switch
Apr 28, 2026
Merged

C++: Fix join-order problem in getNextSwitchCase#21765
jketema merged 4 commits intogithub:mainfrom
jketema:switch

Conversation

@jketema
Copy link
Copy Markdown
Contributor

@jketema jketema commented Apr 28, 2026

See individual commit messages for further details.

jketema added 2 commits April 28, 2026 15:44
Before on `neovim`:
```
[2026-04-28 14:54:20] Evaluated non-recursive predicate Stmt::SwitchCase.getNextSwitchCase/0#dispred#2d3cb6d3@ac8178o2 in 68ms (size: 20848).
Evaluated relational algebra for predicate Stmt::SwitchCase.getNextSwitchCase/0#dispred#2d3cb6d3@ac8178o2 with tuple counts:
           21888  ~0%    {2} r1 = SCAN switch_case OUTPUT In.2, In.0
           21888  ~0%    {4}    | JOIN WITH #switch_caseMerge_21#join_rhs ON FIRST 1 OUTPUT Lhs.1, Lhs.0, _, Rhs.1
           21888  ~4%    {3}    | REWRITE WITH Tmp.2 := 1, Out.2 := (In.3 - Tmp.2) KEEPING 3
        24091916  ~0%    {3}    | JOIN WITH switch_case ON FIRST 1 OUTPUT Lhs.2, Rhs.2, Lhs.1
           20848  ~2%    {2}    | JOIN WITH #switch_caseMerge_12#join_rhs ON FIRST 2 OUTPUT Lhs.1, Lhs.2
                         return r1
```

After:
```
[2026-04-28 15:30:53] Evaluated non-recursive predicate Stmt::SwitchCase.getNextSwitchCase/0#dispred#2d3cb6d3@bf9801oj in 0ms (size: 20848).
Evaluated relational algebra for predicate Stmt::SwitchCase.getNextSwitchCase/0#dispred#2d3cb6d3@bf9801oj with tuple counts:
        21888  ~0%    {4} r1 = SCAN switch_case OUTPUT In.0, _, In.2, In.1
        21888  ~1%    {3}    | REWRITE WITH Tmp.1 := 1, Out.1 := (In.3 + Tmp.1) KEEPING 3
        20848  ~2%    {2}    | JOIN WITH switch_case ON FIRST 2 OUTPUT Lhs.2, Rhs.2
                      return r1
```
@jketema jketema marked this pull request as ready for review April 28, 2026 14:07
Copilot AI review requested due to automatic review settings April 28, 2026 14:07
@jketema jketema requested a review from a team as a code owner April 28, 2026 14:07
* break;
* }
* ```
* 0 yields `case 5:`, 1 yields `case 6:`, and 2 yields `default:`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 0 yields `case 5:`, 1 yields `case 6:`, and 2 yields `default:`.
* 0 yields `case 1:`, 1 yields `case 2:`, and 2 yields `default:`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by updating the example instead.

Copy link
Copy Markdown
Contributor

@IdrissRio IdrissRio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jketema
Copy link
Copy Markdown
Contributor Author

jketema commented Apr 28, 2026

DCA looks good.

@jketema jketema merged commit c2beef1 into github:main Apr 28, 2026
19 checks passed
@jketema jketema deleted the switch branch April 28, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants